package com.wrial;
/*
 * @Author  Wrial
 * @Date Created in 14:44 2020/8/13
 * @Description
 */

import static java.lang.Integer.*;

public class ParseInt {

    public int parseInt(String str) {
        if (str.length() == 0) return 0;
        Long ans = 0l;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) > '0' && str.charAt(i) < '9') {
                builder.append(str.charAt(i));
            } else {
                return -1;
            }
        }
        String aimStr = builder.toString();
        int b = 1;
        for (int i = 0; i < aimStr.length(); i++) {
            ans += aimStr.charAt(i) * b;
            b = b * 10;
            if ((ans - 1) / MAX_VALUE == 1) {
                throw new RuntimeException("超出最大了");
            }
        }
        return ans.intValue();
    }

    public static void main(String[] args) {
    }
}
